package com.youlai.boot.modules.game.controller;

import com.youlai.boot.common.result.PageResult;
import com.youlai.boot.common.result.Result;
import com.youlai.boot.modules.game.model.form.GameInformForm;
import com.youlai.boot.modules.game.model.query.GameInformQuery;
import com.youlai.boot.modules.game.model.vo.GameInformVO;
import com.youlai.boot.modules.game.service.GameInformService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 游戏通知控制器
 *
 * @author 有来技术团队
 */
@Tag(name = "游戏通知接口")
@RestController
@RequestMapping("/api/v1/game/informs")
@RequiredArgsConstructor
public class GameInformController {

    private final GameInformService gameInformService;

    @Operation(summary = "获取通知分页列表")
    @GetMapping("/page")
    public PageResult<GameInformVO> getInformPage(
            @ParameterObject GameInformQuery queryParams
    ) {
        return gameInformService.getInformPage(queryParams);
    }

    @Operation(summary = "获取通知详情")
    @GetMapping("/{id}")
    public Result<GameInformVO> getInformDetail(
            @Parameter(description = "通知ID") @PathVariable Long id
    ) {
        GameInformVO inform = gameInformService.getInformDetail(id);
        return Result.success(inform);
    }

    @Operation(summary = "标记通知为已读")
    @PutMapping("/{id}/read")
    public Result<Boolean> markAsRead(
            @Parameter(description = "通知ID") @PathVariable Long id
    ) {
        boolean result = gameInformService.markAsRead(id);
        return Result.judge(result);
    }

    @Operation(summary = "创建通知")
    @PostMapping
    public Result<Long> createInform(
            @Validated @RequestBody GameInformForm formData
    ) {
        Long id = gameInformService.createInform(formData);
        return Result.success(id);
    }

    @Operation(summary = "更新通知")
    @PutMapping("/{id}")
    public Result<Boolean> updateInform(
            @Parameter(description = "通知ID") @PathVariable Long id,
            @Validated @RequestBody GameInformForm formData
    ) {
        formData.setId(id);
        boolean result = gameInformService.updateInform(formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除通知")
    @DeleteMapping("/{id}")
    public Result<Boolean> deleteInform(
            @Parameter(description = "通知ID") @PathVariable Long id
    ) {
        boolean result = gameInformService.deleteInform(id);
        return Result.judge(result);
    }
} 